home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-06-28 | 2.9 KB | 89 lines | [TEXT/CWIE] |
- // RedBlackKey.h
-
- #ifndef RedBlackKey_h
- #define RedBlackKey_h
-
- #ifndef RedBlackNode_h
- #include "RedBlackNode.h"
- #endif
-
- template < class Key > class RedBlackKeyTree;
- template < class Key > class RedBlackKeyLoop;
-
- template < class KeyType >
- class RedBlackKey: private RedBlackNode
- {
- friend class RedBlackKeyTree< KeyType >;
- friend class RedBlackKeyLoop< KeyType >;
-
- typedef RedBlackKey< KeyType > Node;
- typedef RedBlackKeyTree< KeyType > TreeType;
- typedef RedBlackNode NodeBase;
- typedef RedBlackTree TreeBase;
-
- private:
- KeyType key;
-
- static Node *DownCast( NodeBase *n ) { return static_cast< Node* >( n ); }
- static const Node *DownCast( const NodeBase *n ) { return static_cast< const Node* >( n ); }
-
- static TreeType& DownCast( TreeBase& n );
- static const TreeType& DownCast( const TreeBase& n );
-
- public:
- RedBlackKey( const KeyType& theKey )
- : key( theKey )
- {}
-
- const KeyType& Key() const { return key; }
- void SetKey( const KeyType& );
-
- NodeBase::Owned;
- TreeType& Owner() { return DownCast( NodeBase::Owner() ); }
- const TreeType& Owner() const { return DownCast( NodeBase::Owner() ); }
-
- Node *Parent() { return DownCast( NodeBase::Parent() ); }
- const Node *Parent() const { return DownCast( NodeBase::Parent() ); }
-
- Node *Left() { return DownCast( NodeBase::Left() ); }
- const Node *Left() const { return DownCast( NodeBase::Left() ); }
-
- Node *Right() { return DownCast( NodeBase::Right() ); }
- const Node *Right() const { return DownCast( NodeBase::Right() ); }
-
- Node *Next() { return DownCast( NodeBase::Next() ); }
- const Node *Next() const { return DownCast( NodeBase::Next() ); }
-
- Node *Previous() { return DownCast( NodeBase::Previous() ); }
- const Node *Previous() const { return DownCast( NodeBase::Previous() ); }
-
- Node *Sibling() { return DownCast( NodeBase::Sibling() ); }
- const Node *Sibling() const { return DownCast( NodeBase::Sibling() ); }
-
- bool operator==( const Node& n ) const { return this == &n; }
- bool operator!=( const Node& n ) const { return this != &n; }
- bool operator>=( const Node& n ) const { return key >= n.key; }
- bool operator<=( const Node& n ) const { return key <= n.key; }
- bool operator>( const Node& n ) const { return key > n.key; }
- bool operator<( const Node& n ) const { return key < n.key; }
-
- bool operator==( const KeyType& n ) const { return key == n; }
- bool operator!=( const KeyType& n ) const { return key != n; }
- bool operator>=( const KeyType& n ) const { return key >= n; }
- bool operator<=( const KeyType& n ) const { return key <= n; }
- bool operator>( const KeyType& n ) const { return key > n; }
- bool operator<( const KeyType& n ) const { return key < n; }
-
- NodeBase::IsRoot;
- NodeBase::IsLeftChild;
- NodeBase::IsRightChild;
-
- NodeBase::HasLeftChild;
- NodeBase::HasRightChild;
- NodeBase::IsLeaf;
-
- NodeBase::Depth;
- };
-
- #endif
-